package com.fduss.mazegame.server;

import com.fduss.mazegame.core.maze.Map;
import com.fduss.mazegame.core.maze.Maze;
import com.fduss.mazegame.core.unit.End;
import com.fduss.mazegame.core.unit.Hero;
import com.fduss.mazegame.core.unit.Monster;
import com.fduss.mazegame.util.StackArray;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author duocai wu
 * @Date 2017/10/20
 * @Time 21:11
 */
public class StoryServer extends Server {

    private List<ServerSpec> serverSpecs = new ArrayList<>();

    public StoryServer(ServerSpec spec) {
        super(spec);
        int basicRow = 7;
        int basicCol = 25;
        for (int i = 0; i < 4; i++) {
            serverSpecs.add(new ServerSpecPrim(basicRow + i * 4, basicCol + i * 8, 2));
        }
        hero = serverSpecs.get(0).generateHero();
    }

    public void initLevel(int i) {
        ServerSpec spec = serverSpecs.get(i);
        Map map = spec.generateMap();
        End end = spec.generateEnd();
        Hero old = spec.generateHero();
        old.getPlace().rmEntity(old);
        hero.setPlace(map.getPlace(0, 0));
        Monster[] monsters = spec.generateMonsters();
        int trailCapacity = spec.generateTrailCapacity();
        this.maze = new Maze(map, end, hero, monsters, trailCapacity);
        undo = new StackArray<>();
    }

    public int getLevelNum() {
        return serverSpecs.size();
    }
}

